/**
 * $$
 * if dp[i-1][k-1] + a_i >= 0 dp[i][k] = max(dp[i-1][k-1] + a[i], dp[i-1][k])
 * else dp[i][k] = dp[i-1][k]
 * $$
 */

#define this_doesnt_work 1

#if not this_doesnt_work
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2000+7;
int n;
ll a[maxn], dp[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin>>n; for(int i=1; i<=n; ++i) cin>>a[i];
  for(int i=1; i<=n; ++i) {      // Consider only first |i| potions
    for(int k=1; k<=n; ++k) {    // Drink no more than |k| potions
      if(dp[i-1][k-1]+a[i]>=0) { // You may drink it without being killed
        dp[i][k] = max(dp[i-1][k-1]+a[i], // To drink...
                      dp[i-1][k]);        // ...or not to drink
      }
      else dp[i][k] = dp[i-1][k];         // You'll surely be killed, don't touch it
    }
  }
  #ifndef ONLINE_JUDGE
  for(int i=0; i<=n; ++i, cout.put('\n'))for(int k=0; k<=n; ++k) cout<<dp[i][k]<<' ';
  #endif
  // And congratulations!
  // It's unbelievable that you survived after drinking so much.
  cout<<dp[n][n]<<'\n';
}
#endif

#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	int n; cin >> n;
	priority_queue<long long, vector<long long>, greater<long long> > pq;
	long long S = 0;

	for(int i = 1;i <= n;i++){
		long long x; cin >> x;
		S += x;
		pq.push(x);

		while(S < 0){
			S -= pq.top();
			pq.pop();
		}
	}

	cout << (int) pq.size();
}
